package joSaysHello.shared.entity;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * the Hello entities represent greetings from logged-in users
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "false")
public class Hello implements Serializable
{
	private static final long serialVersionUID = 5934511983136943148L;
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	String key;
	@Persistent//(defaultFetchGroup = "true") // doesn't work on gae datastore...
	private User who;
	@Persistent
	private Date when;

	public Hello(User who, Date when) {
		this.who = who;
		this.when = when;
	}
	@SuppressWarnings("unused")
	private Hello()
	{}
	
	public User getWho() {
		return who;
	}

	public void setWho(User who) {
		this.who = who;
	}

	public String getKey() {
		return key;
	}

	public Date getWhen() {
		return when;
	}

	public void setWhen(Date when) {
		this.when = when;
	}
	
	@Override
	public String toString() {
		return when + ": Hello from " + who;
	}
	
	public String printFull()
	{
		return key + " - " + when + ": Hello from " + who.printFull();
	}

}
